package own.stu.jobgib.playown.zookeeper;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

import java.nio.charset.StandardCharsets;

public class ZkClient {

    public static void main3(String[] args) {
        String x = "{\"name\":\"opms-web\",\"id\":\"64e13351-b1fe-4683-945c-878ddc5ddf44\",\"address\":\"192.168.1.136\",\"port\":0,\"sslPort\":null";
        System.out.println(x.indexOf("\"port\":0"));
        x = x.replace("\"port\":0", "\"port\":8090");
        System.out.println(x);
    }
    public static void main(String[] args) throws Exception {
        String zkServerAddress = "10.224.18.136:2181";
        ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000,3,5000);
        CuratorFramework zkClient = CuratorFrameworkFactory.builder()
                .connectString(zkServerAddress)
                .sessionTimeoutMs(5000)
                .connectionTimeoutMs(5000)
                .retryPolicy(retryPolicy)
                .build();
        //很重要 一定要调用start来创建session链接
        zkClient.start();

        byte[] bytes = zkClient.getData().forPath("/ad_dev/cloud/ody-channel-web");
        System.out.println(new String(bytes, StandardCharsets.UTF_8));

//        zkClient.getData().forPath()

        /*try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
    }
}

